/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#ifndef TAR_HEADER_H
#define TAR_HEADER_H

#include <pltypes.h>
using namespace std;

/**
 * The simple (base) tar header.
 */
class TarHeader {
public:
    enum FileType {
        /**
         * Normal file
         */
        NormalFile          = 0,
        /**
         * Hard link
         */
        HardLink            = 1,
        /**
         * Symbolic link
         */
        SymbolicLink        = 2,
        /**
         * Character special
         */
        CharacterSpecial    = 3,
        /**
         * Block special
         */
        BlockSpecial        = 4,
        /**
         * Directory
         */
        Directory           = 5,
        /**
         * FIFO
         */
        FIFO                = 6,
        /**
         * Contiguous file
         */
        ContiguousFile      = 7
    };
    /**
     * Constructor.
     */
    TarHeader();
    /**
     * The filename.
     */
    char name[100];
    /**
     * The permissions.
     */
    char mode[8];
    /**
     * User ID.
     */
    char uid[8];
    /**
     * Group ID.
     */
    char gid[8];
    /**
     * Size, in bytes (octal).
     */
    char size[12];
    /**
     * Modification time.
     */
    char mtime[12];
    /**
     * Header checksum.
     */
    char chksum[8];
    /**
     * Link type:<br>
     * 0 = Normal file<br>
     * \0 = Normal file (now obsolete)<br>
     * 1 = Hard link<br>
     * 2 = Symbolic link<br>
     * 3 = Character special<br>
     * 4 = Block special<br>
     * 5 = Directory<br>
     * 6 = FIFO<br>
     * 7 = Contiguous file
     */
    char link;
    /**
     * Linked-to file name.
     */
    char linkname[100];
    /**
     * Get the size of the file.
     *
     * @return The size.
     */
    uint32_t fileSize();
    /**
     * Get the filetype from the tar file.
     *
     * @return The filetype.
     */
    TarHeader::FileType fileType();
} __attribute__((packed));

#endif
